package com.qfedu.dao.impl;

import com.qfedu.dao.LoanDao;
import com.qfedu.pojo.Loan;
import com.qfedu.pojo.MyLoan;
import com.qfedu.pojo.MyProduct;
import com.qfedu.pojo.Product;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class LoanDaoImpl  extends BaseDao implements LoanDao {
    @Override
    public List<Loan> findAllLoan() {
        String sql = "select * from bank_loan";
        return queryForList(Loan.class,sql);
    }

    @Override
    public Loan findLoanById(int id) {
        String sql = "select * from bank_loan where pid = ?";
        return queryForOne(Loan.class,sql,id);
    }

    @Override
    public void addLoan(String idcode, int pid, BigDecimal pnum,int back,String pname, int loan_f) {
        String sql = "insert into bank_myloan values(?,?,?,?,?,?,?,?)";
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd ");
        String format = simpleDateFormat.format(date);
        update(sql,null,pid,idcode,pname,pnum,format,back,loan_f);
    }

    @Override
    public List<MyLoan> findMyLoan(String idcode) {
        String sql="SELECT * FROM bank_myloan where idcode=?";
        return queryForList(MyLoan.class,sql,idcode);
    }
}
